home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / MSG Demo 1.4 / source / Demo ƒ / demo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  10.4 KB  |  311 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        demo.c
  4.  
  5. Purpose:    This module handles demo initialization/shutdown and a
  6.             dispatch for the graphic effects and fades.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "demo.h"
  26. #include "demo crash.h"
  27. #include "graphics.h"
  28. #include "demo graphics.h"
  29. #include "wipe headers.h"
  30. #include "reversed wipe headers.h"
  31. #include "fade headers.h"
  32. #include "reversed fade headers.h"
  33. #include "program globals.h"
  34. #include "prefs.h"
  35. #include "menus.h"
  36. #include "file management.h"
  37.  
  38. typedef pascal int (*wipeProcPtr)(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect);
  39. typedef pascal int (*fadeProcPtr)(Rect boundsRect, Pattern *thePattern);
  40.  
  41. unsigned char    gIsReversed;
  42. unsigned char    gWhichPict;
  43. int                gWipeStatus;
  44. int                gWhichWipe;
  45. int                gLastWipe;
  46. wipeProcPtr        gTheWipe[NUM_WIPES+1], gTheReverseWipe[NUM_WIPES+1];
  47. fadeProcPtr        gTheFade[NUM_WIPES+1], gTheReverseFade[NUM_WIPES+1];
  48.  
  49. void InitTheProgram(void)
  50. {
  51.     int                index;
  52.     
  53.     InitFiles();
  54.     
  55.     if (gIsReversed)
  56.         ReverseAllWipes();
  57.     
  58.     gWhichWipe=0;
  59.     
  60.     (**(gTheWindowData[kMainWindow])).dispatchProc=MainWindowDispatch;        /* demo graphics.c */
  61.     ((**(gTheWindowData[kMainWindow])).dispatchProc)(gTheWindowData[kMainWindow], kStartup, 0L);
  62.     
  63.     index=1;
  64.     gTheFade[index++]=BoxOutFade;
  65.     gTheFade[index++]=RandomFade;
  66.     gTheFade[index++]=SpiralGyraFade;
  67.     gTheFade[index++]=CircularFade;
  68.     gTheFade[index++]=0L;                    /* CasteWipeRL can't be a fade */
  69.     gTheFade[index++]=FourCornerFade;
  70.     gTheFade[index++]=BoxInFade;
  71.     gTheFade[index++]=0L;                    /* RippleWipe can't be a fade */
  72.     gTheFade[index++]=0L;                    /* DissolveWipe can't easily be a fade */
  73.     gTheFade[index++]=DiagonalFade;
  74.     gTheFade[index++]=0L;                /* CasteWipe can't be a fade */
  75.     gTheFade[index++]=HilbertFade;
  76.     gTheFade[index++]=SlideFade;
  77.     gTheFade[index++]=SkipalineFade;
  78.     gTheFade[index++]=SkipalineLRFade;
  79.     gTheFade[index++]=ScissorsFade;
  80.     gTheFade[index++]=RescueRaidersFade;
  81.     gTheFade[index++]=FourCornerCenteredFade;
  82.     gTheFade[index++]=TwoCornerFade;
  83.     gTheFade[index++]=CircleOutFade;
  84.     gTheFade[index++]=CircleInFade;
  85.     gTheFade[index++]=CircleSerendipityFade;
  86.     gTheFade[index++]=CircleBulgeFade;
  87.     gTheFade[index++]=CornerCircleFade;
  88.     gTheFade[index++]=QuadrantFade;
  89.     gTheFade[index++]=QuadrantFade2;
  90.     gTheFade[index++]=Skipaline2PassFade;
  91.     gTheFade[index++]=SkipalineLR2PassFade;
  92.     gTheFade[index++]=HGRFade;
  93.     gTheFade[index++]=HGR2Fade;
  94.     gTheFade[index++]=FullScrollLRFade;
  95.     gTheFade[index++]=FullScrollUDFade;
  96.     gTheFade[index++]=MrDoFade;
  97.     gTheFade[index++]=MrDoOutdoneFade;
  98.     gTheFade[index++]=SplitScrollUDFade;
  99.     gTheFade[index++]=FourCornerScrollFade;
  100.     gTheFade[index++]=HalvesScrollFade;
  101.     gTheFade[index++]=PourScrollFade;
  102.     gTheFade[index++]=QuadrantScrollFade;
  103.     gTheFade[index++]=QuadrantScroll2Fade;
  104.     if (index!=NUM_WIPES+1)
  105.         Debugger();
  106.     
  107.     index=1;
  108.     gTheReverseFade[index++]=BoxInFade;
  109.     gTheReverseFade[index++]=RandomFade;
  110.     gTheReverseFade[index++]=0L;                /* Spiral Gyra can't be easily reversed. */
  111.     gTheReverseFade[index++]=CircularFadeReversed;
  112.     gTheReverseFade[index++]=0L;                /* CasteWipeRight can't be a fade */
  113.     gTheReverseFade[index++]=FourCornerFadeReversed;
  114.     gTheReverseFade[index++]=BoxOutFade;
  115.     gTheReverseFade[index++]=0L;                /* RippleWipe Reversed can't be a fade */
  116.     gTheReverseFade[index++]=0L;                /* DissolveWipe can't easily be a fade */
  117.     gTheReverseFade[index++]=DiagonalFadeDownRight;
  118.     gTheReverseFade[index++]=0L;                /* CasteWipeDown can't be a fade */
  119.     gTheReverseFade[index++]=HilbertFadeReversed;
  120.     gTheReverseFade[index++]=SlideFadeReversed;
  121.     gTheReverseFade[index++]=SkipalineFade;
  122.     gTheReverseFade[index++]=SkipalineLRFade;
  123.     gTheReverseFade[index++]=ScissorsFadeReversed;
  124.     gTheReverseFade[index++]=RescueRaidersFadeReversed;
  125.     gTheReverseFade[index++]=FourCenteredFadeReversed;
  126.     gTheReverseFade[index++]=TwoCornerFadeReversed;
  127.     gTheReverseFade[index++]=CircleInFade;
  128.     gTheReverseFade[index++]=CircleOutFade;
  129.     gTheReverseFade[index++]=0L;                /* CircleSerendipity can't be easily reversed */
  130.     gTheReverseFade[index++]=0L;                /* CircleBulge can't be easily reversed */
  131.     gTheReverseFade[index++]=CornerCircleFadeReversed;
  132.     gTheReverseFade[index++]=QuadrantFadeReversed;
  133.     gTheReverseFade[index++]=QuadrantFade2Reversed;
  134.     gTheReverseFade[index++]=Skipaline2PassFadeReversed;
  135.     gTheReverseFade[index++]=SkipalineLR2PassFadeReversed;
  136.     gTheReverseFade[index++]=HGRFadeReversed;
  137.     gTheReverseFade[index++]=HGR2FadeReversed;
  138.     gTheReverseFade[index++]=FullScrollLeftFade;
  139.     gTheReverseFade[index++]=FullScrollUpFade;
  140.     gTheReverseFade[index++]=MrDoFadeReversed;
  141.     gTheReverseFade[index++]=MrDoOutdoneFadeReversed;
  142.     gTheReverseFade[index++]=0L;                /* SplitScrollUD can't be reversed */
  143.     gTheReverseFade[index++]=0L;                /* FourCornerScroll can't be reversed */
  144.     gTheReverseFade[index++]=HalvesScrollFadeReversed;
  145.     gTheReverseFade[index++]=PourScrollFadeReversed;
  146.     gTheReverseFade[index++]=QuadrantScrollFadeReversed;
  147.     gTheReverseFade[index++]=QuadrantScroll2FadeReversed;
  148.     if (index!=NUM_WIPES+1)
  149.         Debugger();
  150.     
  151.     index=1;
  152.     gTheWipe[index++]=BoxOutWipe;
  153.     gTheWipe[index++]=RandomWipe;
  154.     gTheWipe[index++]=SpiralGyra;
  155.     gTheWipe[index++]=CircularWipe;
  156.     gTheWipe[index++]=CasteWipeRL;
  157.     gTheWipe[index++]=FourCorner;
  158.     gTheWipe[index++]=BoxInWipe;
  159.     gTheWipe[index++]=RippleWipe;
  160.     gTheWipe[index++]=DissolveWipe;
  161.     gTheWipe[index++]=DiagonalWipe;
  162.     gTheWipe[index++]=CasteWipe;
  163.     gTheWipe[index++]=HilbertWipe;
  164.     gTheWipe[index++]=SlideWipe;
  165.     gTheWipe[index++]=Skipaline;
  166.     gTheWipe[index++]=SkipalineLR;
  167.     gTheWipe[index++]=Scissors;
  168.     gTheWipe[index++]=RescueRaiders;
  169.     gTheWipe[index++]=FourCornerCentered;
  170.     gTheWipe[index++]=TwoCorner;
  171.     gTheWipe[index++]=CircleOut;
  172.     gTheWipe[index++]=CircleIn;
  173.     gTheWipe[index++]=CircleSerendipity;
  174.     gTheWipe[index++]=CircleBulge;
  175.     gTheWipe[index++]=CornerCircle;
  176.     gTheWipe[index++]=QuadrantWipe;
  177.     gTheWipe[index++]=QuadrantWipe2;
  178.     gTheWipe[index++]=Skipaline2Pass;
  179.     gTheWipe[index++]=SkipalineLR2Pass;
  180.     gTheWipe[index++]=HGR;
  181.     gTheWipe[index++]=HGR2;
  182.     gTheWipe[index++]=FullScrollLR;
  183.     gTheWipe[index++]=FullScrollUD;
  184.     gTheWipe[index++]=MrDo;
  185.     gTheWipe[index++]=MrDoOutdone;
  186.     gTheWipe[index++]=SplitScrollUD;
  187.     gTheWipe[index++]=FourCornerScroll;
  188.     gTheWipe[index++]=HalvesScroll;
  189.     gTheWipe[index++]=PourScroll;
  190.     gTheWipe[index++]=QuadrantScroll;
  191.     gTheWipe[index++]=QuadrantScroll2;
  192.     if (index!=NUM_WIPES+1)
  193.         Debugger();
  194.     
  195.     index=1;
  196.     gTheReverseWipe[index++]=BoxInWipe;
  197.     gTheReverseWipe[index++]=RandomWipe;
  198.     gTheReverseWipe[index++]=0L;            /* Spiral Gyra can't be easily reversed */
  199.     gTheReverseWipe[index++]=CircularWipeReversed;
  200.     gTheReverseWipe[index++]=CasteWipeRight;
  201.     gTheReverseWipe[index++]=FourCornerReversed;
  202.     gTheReverseWipe[index++]=BoxOutWipe;
  203.     gTheReverseWipe[index++]=RippleWipeReversed;
  204.     gTheReverseWipe[index++]=DissolveWipe;
  205.     gTheReverseWipe[index++]=DiagonalWipeDownRight;
  206.     gTheReverseWipe[index++]=CasteWipeDown;
  207.     gTheReverseWipe[index++]=HilbertWipeReversed;
  208.     gTheReverseWipe[index++]=SlideWipeReversed;
  209.     gTheReverseWipe[index++]=Skipaline;
  210.     gTheReverseWipe[index++]=SkipalineLR;
  211.     gTheReverseWipe[index++]=ScissorsReversed;
  212.     gTheReverseWipe[index++]=RescueRaidersReversed;
  213.     gTheReverseWipe[index++]=FourCornerCenteredReversed;
  214.     gTheReverseWipe[index++]=TwoCornerReversed;
  215.     gTheReverseWipe[index++]=CircleIn;
  216.     gTheReverseWipe[index++]=CircleOut;
  217.     gTheReverseWipe[index++]=0L;            /* CircleSerendipity can't be easily reversed */
  218.     gTheReverseWipe[index++]=0L;            /* CircleBulge can't be easily reversed */
  219.     gTheReverseWipe[index++]=CornerCircleReversed;
  220.     gTheReverseWipe[index++]=QuadrantWipeReversed;
  221.     gTheReverseWipe[index++]=QuadrantWipe2Reversed;
  222.     gTheReverseWipe[index++]=Skipaline2PassReversed;
  223.     gTheReverseWipe[index++]=SkipalineLR2PassReversed;
  224.     gTheReverseWipe[index++]=HGRReversed;
  225.     gTheReverseWipe[index++]=HGR2Reversed;
  226.     gTheReverseWipe[index++]=FullScrollLeft;
  227.     gTheReverseWipe[index++]=FullScrollUp;
  228.     gTheReverseWipe[index++]=MrDoReversed;
  229.     gTheReverseWipe[index++]=MrDoOutdoneReversed;
  230.     gTheReverseWipe[index++]=0L;            /* SplitScrollUD can't be reversed */
  231.     gTheReverseWipe[index++]=0L;            /* FourCornerScroll can't be reversed */
  232.     gTheReverseWipe[index++]=HalvesScrollReversed;
  233.     gTheReverseWipe[index++]=PourScrollReversed;
  234.     gTheReverseWipe[index++]=QuadrantScrollReversed;
  235.     gTheReverseWipe[index++]=QuadrantScroll2Reversed;
  236.     if (index!=NUM_WIPES+1)
  237.         Debugger();
  238. }
  239.  
  240. void ShutDownTheProgram(void)
  241. {
  242.     ((**(gTheWindowData[kMainWindow])).dispatchProc)(gTheWindowData[kMainWindow], kShutdown, 0L);
  243.     SaveThePrefs();
  244. }
  245.  
  246. void DoFullScreenFade(int whichWipe)
  247. {
  248.     Rect            theRect;
  249.     int                oldMenuBarHeight;
  250.  
  251.     ObscureCursor();
  252.     oldMenuBarHeight=GetMBarHeight();
  253.     MBarHeight=0;
  254.     DrawMenuBar();
  255.     SetPort(WMgrPort);
  256.     theRect=WMgrPort->portRect;
  257.     
  258.     gWhichWipe=whichWipe;
  259.     FadeDispatch(theRect);
  260.     RestoreScreen(oldMenuBarHeight);    
  261.     gLastWipe=gWhichWipe;
  262.     gWhichWipe=0;
  263. }
  264.  
  265. void FadeDispatch(Rect theRect)
  266. {
  267.     if (gIsReversed)
  268.     {
  269.         if (gTheReverseFade[gWhichWipe]!=0L)
  270.             gTheReverseFade[gWhichWipe](theRect, &black);
  271.     }
  272.     else
  273.     {
  274.         if (gTheFade[gWhichWipe]!=0L)
  275.             gTheFade[gWhichWipe](theRect, &black);
  276.     }
  277. }
  278.  
  279. void WipeDispatch(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect theRect)
  280. {
  281.     ObscureCursor();
  282.  
  283.     gWhichPict = !gWhichPict;
  284.     
  285.     if ((gWipeStatus==kFadesPlusEffects) || (gWipeStatus==kFadesPlusReverseEffects))
  286.         FadeDispatch(theRect);
  287.     if (gWipeStatus==kFadesPlusReverseEffects)
  288.         gIsReversed=!gIsReversed;
  289.     
  290.     if (gIsReversed)
  291.     {
  292.         if (gTheReverseWipe[gWhichWipe]!=0L)
  293.             gTheReverseWipe[gWhichWipe](sourceGrafPtr, destGrafPtr, theRect);
  294.         else
  295.             CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits), &theRect, &theRect, 0, 0L);
  296.     }
  297.     else
  298.     {
  299.         if (gTheWipe[gWhichWipe]!=0L)
  300.             gTheWipe[gWhichWipe](sourceGrafPtr, destGrafPtr, theRect);
  301.         else
  302.             CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits), &theRect, &theRect, 0, 0L);
  303.     }
  304.     
  305.     if (gWipeStatus==kFadesPlusReverseEffects)
  306.         gIsReversed=!gIsReversed;
  307.     
  308.     gLastWipe=gWhichWipe;
  309.     gWhichWipe=0;
  310. }
  311.